package com.right.health.app.ui.registered.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.magic.basic.adapter.BaseAbsAdapter;
import com.right.health.app.R;
import com.right.health.app.bean.DoctorBean;
import com.right.health.app.utils.GlideUtil;

/*
 * Created by hopeliao on 2019-09-24
 *
 */
public class FindDoctorAdapter extends BaseAbsAdapter<DoctorBean> {

    private View.OnClickListener mClickListener;

    public void setOnClickListener(View.OnClickListener listener) {
        this.mClickListener = listener;
    }

    public FindDoctorAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.find_doctor_item, null);
            viewHolder = new ViewHolder();
            viewHolder.contentImage = (ImageView) convertView.findViewById(R.id.iv_avatar);
            viewHolder.nameTv = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.fansTv = convertView.findViewById(R.id.tv_fans);
            viewHolder.departmentTv = convertView.findViewById(R.id.tv_department);
            viewHolder.skillTv = convertView.findViewById(R.id.tv_skill);
            viewHolder.stateTv = convertView.findViewById(R.id.tv_state);
            viewHolder.typeIv = convertView.findViewById(R.id.iv_type);
            viewHolder.freeTv = convertView.findViewById(R.id.tv_consult_free);
            viewHolder.picTv = convertView.findViewById(R.id.tv_consult_pic);

            if(mClickListener != null) {
            }
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        DoctorBean bean = mDataSource.get(position);
        viewHolder.fansTv.setText(String.valueOf(bean.getFans()));
        viewHolder.nameTv.setText(bean.getDoctorname());
        viewHolder.departmentTv.setText(String.format("%s | %s","",""));
        viewHolder.skillTv.setText(getString(R.string.doctor_skilled_text, bean.getDoctordesc()));
        if (!TextUtils.isEmpty(bean.getImageurl())) {
            Glide.with(mContext).load(bean.getImageurl()).apply(GlideUtil.getAvatarPlaceholder()).into(viewHolder.contentImage);
        }
        if (TextUtils.equals(bean.getRoletype(),"1")){
            viewHolder.typeIv.setImageResource(R.mipmap.ic_find_doctor_identity_nurse);
        }else if (TextUtils.equals(bean.getRoletype(),"2")){
            viewHolder.typeIv.setImageResource(R.mipmap.ic_find_doctor_identity_doctor);
        }

      /*  if (bean.isIsonline()){
            viewHolder.stateTv.setText(R.string.online_text);
            viewHolder.stateTv.setTextColor(getResources().getColor(R.color.color_06b3ae));
        }else{
            viewHolder.stateTv.setText(R.string.offline_text);
            viewHolder.stateTv.setTextColor(getResources().getColor(R.color.color_999999));
        }*/
        return convertView;
    }


    private class ViewHolder {
        private ImageView contentImage,typeIv;
        private TextView nameTv,departmentTv,skillTv,stateTv,fansTv,freeTv,picTv;
    }
}
